using Microsoft.EntityFrameworkCore;
using PandaWebAPI.Models.ef;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace PandaWebAPI.Services
{
    public class UserService : BaseService<User>, IUserService
    {
        public UserService(PandaSystemContext context) : base(context)
        {
        }

        public async Task<List<User>> GetAllUsersAsync()
        {
            return await _context.Users.ToListAsync();
        }

        public async Task AddUserAsync(User user)
        {
            _context.Users.Add(user);
            await _context.SaveChangesAsync();
        }

        public async Task UpdateUserAsync(User user)
        {
            _context.Entry(user).State = EntityState.Modified;
            await _context.SaveChangesAsync();
        }

        public async Task DeleteUserAsync(Guid id)
        {
            var user = await _context.Users.FindAsync(id);
            if (user != null)
            {
                _context.Users.Remove(user);
                await _context.SaveChangesAsync();
            }
        }
    }
}